# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# if you are cross-compiling, you need to point to the right executables
# and change the flags to ld and the build procedure for as

GCCDIR = ../../../gnu-decstation-ultrix/decstation-ultrix/2.95.3/

LDFLAGS = -T script -N
ASFLAGS = -mips2
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)

PATH = $(GCCDIR):/lib:/usr/bin:/bin

CC = $(GCCDIR)gcc -B../../../gnu-decstation-ultrix/
AS = $(GCCDIR)as
LD = $(GCCDIR)ld

CPP = gcc -E
INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt shell matmult sort brasil ls pwd create Open close read write cat rm mv rmdir mkdir cd cp

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.c > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

execute.o: execute.c
	$(CC) $(CFLAGS) -c execute.c
execute: execute.o execute.o
	$(LD) $(LDFLAGS) start.o execute.o -o execute.coff
	../bin/coff2noff execute.coff execute	
	
yield.o:
	$(CC) $(CFLAGS) -c yield.c
yield: yield.o start.o	
	$(LD) $(LDFLAGS) start.o yield.o -o yield.coff
	../bin/coff2noff yield.coff yield
	
halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

brasil.o: brasil.c
	$(CC) $(CFLAGS) -c brasil.c
brasil: brasil.o start.o
	$(LD) $(LDFLAGS) start.o brasil.o -o brasil.coff
	../bin/coff2noff brasil.coff brasil	
	
shell.o: shell.c
	$(CC) $(CFLAGS) -c shell.c
shell: shell.o start.o
	$(LD) $(LDFLAGS) start.o shell.o -o shell.coff
	../bin/coff2noff shell.coff shell

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult
	
ls.o: ls.c
	$(CC) $(CFLAGS) -c ls.c
ls: ls.o start.o
	$(LD) $(LDFLAGS) start.o ls.o -o ls.coff
	../bin/coff2noff ls.coff ls
	
pwd.o: pwd.c
	$(CC) $(CFLAGS) -c pwd.c
pwd: pwd.o start.o
	$(LD) $(LDFLAGS) start.o pwd.o -o pwd.coff
	../bin/coff2noff pwd.coff pwd	
	
create.o: create.c
	$(CC) $(CFLAGS) -c create.c
create: create.o start.o
	$(LD) $(LDFLAGS) start.o create.o -o create.coff
	../bin/coff2noff create.coff create		
	
Open.o: Open.c
	$(CC) $(CFLAGS) -c Open.c
Open: Open.o start.o
	$(LD) $(LDFLAGS) start.o Open.o -o Open.coff
	../bin/coff2noff Open.coff Open		
	
close.o: close.c
	$(CC) $(CFLAGS) -c close.c
close: close.o start.o
	$(LD) $(LDFLAGS) start.o close.o -o close.coff
	../bin/coff2noff close.coff close			
	
read.o: read.c
	$(CC) $(CFLAGS) -c read.c
read: read.o read.o
	$(LD) $(LDFLAGS) start.o read.o -o read.coff
	../bin/coff2noff read.coff read

write.o: write.c
	$(CC) $(CFLAGS) -c write.c
write: write.o start.o
	$(LD) $(LDFLAGS) start.o write.o -o write.coff
	../bin/coff2noff write.coff write	
	
cat.o: cat.c
	$(CC) $(CFLAGS) -c cat.c
cat: cat.o start.o
	$(LD) $(LDFLAGS) start.o cat.o -o cat.coff
	../bin/coff2noff cat.coff cat	
	
mkdir.o: mkdir.c
	$(CC) $(CFLAGS) -c mkdir.c
mkdir: mkdir.o start.o
	$(LD) $(LDFLAGS) start.o mkdir.o -o mkdir.coff
	../bin/coff2noff mkdir.coff mkdir		
	
rmdir.o: rmdir.c
	$(CC) $(CFLAGS) -c rmdir.c
rmdir: rmdir.o start.o
	$(LD) $(LDFLAGS) start.o rmdir.o -o rmdir.coff
	../bin/coff2noff rmdir.coff rmdir		
	
cp.o: cp.c
	$(CC) $(CFLAGS) -c cp.c
cp: cp.o start.o
	$(LD) $(LDFLAGS) start.o cp.o -o cp.coff
	../bin/coff2noff cp.coff cp		
	
cd.o: cd.c
	$(CC) $(CFLAGS) -c cd.c
cd: cd.o start.o
	$(LD) $(LDFLAGS) start.o cd.o -o cd.coff
	../bin/coff2noff cd.coff cd		
	
mv.o: mv.c
	$(CC) $(CFLAGS) -c mv.c
mv: mv.o start.o
	$(LD) $(LDFLAGS) start.o mv.o -o mv.coff
	../bin/coff2noff mv.coff mv		

rm.o: rm.c
	$(CC) $(CFLAGS) -c rm.c
rm: rm.o start.o
	$(LD) $(LDFLAGS) start.o rm.o -o rm.coff
	../bin/coff2noff rm.coff rm		
	
	